package org.example.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.mapper.DStaffMapper;
import org.example.pojo.DStaff;
import org.example.pojo.DStaffRecord;
import org.example.pojo.select.DStaffRecordSelect;
import org.example.service.DStaffRecordService;
import org.example.mapper.DStaffRecordMapper;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
* @author chenhongkai
* @description 针对表【d_staff_record(人员宿舍变动)】的数据库操作Service实现
* @createDate 2024-07-17 14:53:38
*/
@Service
public class DStaffRecordServiceImpl extends ServiceImpl<DStaffRecordMapper, DStaffRecord>
    implements DStaffRecordService{

    @Autowired
    private DStaffRecordMapper dStaffRecordMapper;

    @Override
    public Result<Map> selectAll(DStaffRecordSelect dStaffRecordSelect) {
        //分页查询员工
        Page<DStaff> page = new Page<>(dStaffRecordSelect.getCurrentPage(),dStaffRecordSelect.getPageSize());
        page.setSearchCount(false);
        Integer staffRecordsTotal = dStaffRecordMapper.SelectAllStaffRecordsTotal(dStaffRecordSelect);
        page.setTotal(staffRecordsTotal);
        IPage<Map> mapIPage = dStaffRecordMapper.SelectAllStaffRecords(page,dStaffRecordSelect);

        Map recordMap = new HashMap<>();
        recordMap.put("pageSize",mapIPage.getSize());
        recordMap.put("pageTotal",mapIPage.getTotal());
        recordMap.put("recordData",mapIPage.getRecords());

        return Result.ok(recordMap);
    }
}




